<?php
//No direct access
defined('_JEXEC') or die('Restricted access');
?>
<div id="ownservices">
 <div id="mainmenuownservice"><?php echo MenuHelper::nav(); ?></div>
	<div id="mainownservice">
		<h3><?php echo JText::_('OWNSERVICE_DETAIL_TRANSFER'); ?></h3>
		<hr />
		<div id="toolbar">
			<a class="toolbar" onclick="submitbutton('downloadall');" href="#">
				<span title="<?php echo JText::_('OWNSERVICE_DOWNLOAD'); ?>" class="icon-32-export"></span>
				<?php echo JText::_('OWNSERVICE_DOWNLOAD'); ?>
			</a>
			<a class="toolbar" href="javascript:history.go(-1);">
				<span title="<?php echo JText::_('OWNSERVICE_CLOSE'); ?>" class="icon-32-cancel"></span>
				<?php echo JText::_('OWNSERVICE_CLOSE'); ?>
			</a>
		</div>
		<form name="adminForm" method="post" action="<?php echo JRoute::_('index.php?option=com_ownservice'); ?>">
			<table>
				<tr>
					<td><?php echo JText::_('OWNSERVICE_REQUESTED_DATE_TIME'); ?> :</td>
					<td>
						<?php
							list($date, $time) = @explode(' ', @$this->rows[0]->requested_date);
							echo $this->selectdate.' '.$time; 
						?>
					</td>
				</tr>
			</table>
			<table class="adminlist" cellspacing="1">
				<tr>
					<td align="center" class="tablelist">
						<?php echo JText::_('OWNSERVICE_ACCOUNT_NO'); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JText::_('OWNSERVICE_SENDER'); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JText::_('OWNSERVICE_BANK_NAME'); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JText::_('OWNSERVICE_BRANCH_CITY'); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JText::_('OWNSERVICE_REQUESTED_DATE_TIME'); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JText::_('OWNSERVICE_AMOUNT_TRANSFER'); ?><br /> ( AUD )
					</td>
					<td align="center" class="tablelist">
						<?php echo JText::_('OWNSERVICE_RATE'); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JText::_('OWNSERVICE_TOTAL_EXCHANGE'); ?> <br /> ( THB )
					</td>
				</tr>
				<?php
				$sumall_amount	= 0;
				$sumall_rate	 	= 0;
				$sumall_total		= 0;
				$priceformat 	= OwnserviceHelper::getParams('price_format', '#,###.##');
				$dateformat  	= OwnserviceHelper::getParams('date_format', '%d/%m/%Y');
				if($this->rows):
							foreach($this->rows as $sessions):
				?>
				<tr>
					<td colspan="9">
						<span style="background-color: yellow; border: 1px solid; padding: 5px 5px; clear: both; font-weight: bold;">
							Session : <?php echo $sessions->session; ?>
						</span>
					</td>
				</tr>
				<?php
					$k 			 	= 0;
					$total		 		= 0;
					$sum_amount	= 0;
					$sum_rate	 	= 0;
					$sum_total		= 0;
					$i = 0;
					foreach($sessions->transactions as $i=>$row):
				?>
				<tr class="row<?php echo $i % 2; ?>">
					<td align="center" class="inner_tablelist">
						<?php echo OwnserviceHelper::accountFormat($row->account); ?>
					</td>
					<td class="inner_tablelist">
						<?php echo $row->username; ?>
					</td>
					<td class="inner_tablelist">
						<?php echo $row->bank_name; ?>
					</td>
					<td class="inner_tablelist"> 
						<?php echo $row->branch_city; ?>	
					</td>
					<td class="inner_tablelist" align="center">
						<?php echo JHTML::_('date', $row->requested_date, $dateformat); ?>
					</td>
					<td class="inner_tablelist" align="right" nowrap="nowrap">
						<?php 
							echo OwnserviceHelper::moneyFormat($priceformat,$row->amount); 
							$sum_amount = $sum_amount + $row->amount;
						?> 
					</td>
					<td class="inner_tablelist" align="right" nowrap="nowrap">
						<?php
							$color = '';
							if($row->extrarate > 0.00 ) {
								$color = 'red';
							} else if($row->extrarate < 0.00) {
								$color = 'green';
							}
						?>
						<?php if(!$row->iscore): ?>
							<div style="border-bottom: 1px dotted #ccc;">
								<?php 
									echo OwnserviceHelper::moneyFormat($priceformat,$row->rate_th);
									$sum_rate = $sum_rate + $row->rate_th; 
								?> THB
							</div>
						<?php
							else:
								$sum_rate = $sum_rate + ($row->rate+$row->extrarate);  
							endif; 
						?>
						<div class ="<?php echo $color; ?>">
							<?php 
								echo OwnserviceHelper::moneyFormat($priceformat,$row->rate+$row->extrarate); 
							?> 
						</div>
					</td>
					<td class="inner_tablelist" align="right" nowrap="nowrap">
						<?php 
							/* total transfer */
							$color = '';
							if($row->extratotal > 0.00 ){
								$color = 'red';
								$total = $row->extratotal;	
							} else {
								$total = $row->amount * ($row->rate+$row->extrarate);
							}
						?>
						<?php if(!$row->iscore): ?>
							<div style="border-bottom: 1px dotted #ccc;">
								<?php 
									echo OwnserviceHelper::moneyFormat($priceformat,$row->total_th);
									$sum_total = $sum_total + $row->total_th;
								?> THB
							</div>
						<?php
							else:
								$sum_total = $sum_total + ($total- ($row->bankfee+$row->extrabfee));  
							endif; 
						?>
						<div class="<?php echo $color; ?>">
							<?php echo OwnserviceHelper::moneyFormat($priceformat,($total- ($row->bankfee+$row->extrabfee))); ?>
						</div> 
					</td>
				</tr>
				<?php endforeach; ?>
				<tr>
					<td colspan="5" align="right">
						<strong><?php echo JText::_('OWNSERVICE_TOTAL'); ?></strong>
					</td>
					<td align="right">
						<strong><?php echo OwnserviceHelper::moneyFormat($priceformat,$sum_amount); ?></strong>
					</td>
					<td align="right" style="font-weight: bold;">
						<?php echo OwnserviceHelper::moneyFormat($priceformat,$sum_rate); ?>
					</td>
					<td align="right" style="font-weight: bold;">
						<?php echo OwnserviceHelper::moneyFormat($priceformat,$sum_total); ?>
					</td>
				</tr>
				</tbody>
				<?php 
					$sumall_amount = $sumall_amount +$sum_amount;
					$sumall_rate = $sumall_rate+$sum_rate;
					$sumall_total = $sumall_total+$sum_total;
					endforeach; 
				?>
				<tr>
					<td colspan="9">
						<hr />
					</td>
				</tr>
				<tr>
					<td colspan="5" align="right">
						<strong><?php echo JText::_('OWNSERVICE_TOTAL'); ?></strong>
					</td>
					<td align="right">
						<strong><?php echo OwnserviceHelper::moneyFormat($priceformat,$sumall_amount); ?></strong>
					</td>
					<td align="right" style="font-weight: bold;">
						<?php echo OwnserviceHelper::moneyFormat($priceformat,$sumall_rate); ?>
					</td>
					<td align="right" style="font-weight: bold;">
						<?php echo OwnserviceHelper::moneyFormat($priceformat,$sumall_total); ?>
					</td>
				</tr>
			</table>
			<?php endif; ?>
			<input type="hidden" name="date" value="<?php echo $this->selectdate; ?>" />
			<input type="hidden" name="session" value="<?php echo $this->session; ?>" />
			<input type="hidden" name="option" value="com_ownservice" />
			<input type="hidden" name="task" value="" />
			<input type="hidden" name="Itemid" value="<?php echo JRequest::getVar('Itemid'); ?>" />
			<input type="hidden" name="controller" value="transferhistory" />
			<input type="hidden" name="view" value="transferhistories" />
			<?php echo JHTML::_( 'form.token' ); ?>
		</form>
	</div>
</div>